import { Encrypt } from '../function/encrypt/encrypt';
/**
 * @class 加密密码并传输
 */
export class EncryptTransist {
  private static RSA_Key: string = "" + "-----BEGIN PUBLIC KEY-----" + "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC9IzSUzsgNaQrov7JS5hlFsL1" + "4eXTIU014hh9fy4cpuZ9n0hMq7W40b2qPmqA7v9yu4OvLe2OC+h6u3nfAQrWt9yB" + "htHcEFiNF50gAPDEx9cGdjlrf+lwA9p6o4u1L+zq5l6W7JwxqElT985ytpTAZPro" + "pDOGeEtipKcHjkiNqQIDAQAB" + "-----END PUBLIC KEY-----"; // RSA 公钥
  private Crypto: Encrypt; // 加密容器
  constructor() {
    this.Crypto = new Encrypt();
  }
  /**
   * @function 加密
   */
  public Encrypt = (data: string): {key: string, data: string} => {
    const Key = this.Crypto.encodeRSA(EncryptTransist.RSA_Key);
    const value = this.Crypto.encryptAES(data);
    return {
      data: encodeURIComponent(value), // 转义+号
      key: encodeURIComponent(Key), // 转义+号
    }
  }
}